package com.zhou.zhxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhou.zhxy.mapper.ClazzMapper;
import com.zhou.zhxy.pojo.Clazz;
import com.zhou.zhxy.pojo.Student;
import com.zhou.zhxy.pojo.Teacher;
import com.zhou.zhxy.service.ClazzService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service  初始化 可以指定当前的实现类
 * Transactional  事务
 */
@Service("clazzServiceImpl")
@Transactional
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {
    /**
     * 功能：1、获取班级
     * @return
     */
    @Override
    public List<Clazz> getClazzs() {
        return baseMapper.selectList(null);
    }

    /**
     * 功能：1、分页获取班级
     * @param page
     * @param clazz
     * @return
     */
    @Override
    public IPage<Clazz> getClazzsList(Page<Clazz> page, Clazz clazz) {
        QueryWrapper<Clazz> queryWrapper = null;
        if(clazz != null){
            queryWrapper = new QueryWrapper<>();
            if(clazz.getName() != null){
                queryWrapper.eq("name",clazz.getName());
            }
            if(clazz.getGradeName() != null){
                queryWrapper.eq("grade_name",clazz.getGradeName());
            }
            queryWrapper.orderByDesc("id");
            queryWrapper.orderByAsc("name");
        }
        IPage<Clazz> pages = baseMapper.selectPage(page,queryWrapper);
        return pages;
    }
}
